package com.yaodian100.ec.creditcard.service.impl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

import com.yaodian100.core.common.dao.impl.CommonCriteria;
import com.yaodian100.core.common.exception.CoreException;
import com.yaodian100.core.common.service.impl.DomainServiceImpl;
import com.yaodian100.ec.creditcard.entity.CreditcardSetting;
import com.yaodian100.ec.creditcard.service.CreditcardSettingService;

public class CreditcardSettingServiceImpl extends DomainServiceImpl<CreditcardSetting> implements CreditcardSettingService {
	
	@Override
	public Map<String, CreditcardSetting> getCreditcardSettingMap() {
		Map<String, CreditcardSetting> map = new LinkedHashMap<String, CreditcardSetting>();
		
		CommonCriteria cri = new CommonCriteria();
		cri.addEq("delete", false);
		
		int entitySize = super.getListSize(cri).intValue();
		List<CreditcardSetting> list = super.getList(0, entitySize, cri, new String[] { "id desc" });
		
		for(CreditcardSetting c : list) {
			map.put(c.getId() + "", c);
		}
		
		return map;
	}
	
	@Override
	public List<CreditcardSetting> getList(int firstResult, int maxResults,
			CommonCriteria criteria, String[] sortOrder) throws CoreException {
		if( criteria == null )
			criteria = new CommonCriteria();
		criteria.addEq("delete", false);
		return super.getList(firstResult, maxResults, criteria, sortOrder);
	}
	
	@Override
	public Number getListSize(CommonCriteria criteria) throws CoreException {
		if( criteria == null )
			criteria = new CommonCriteria();
		criteria.addEq("delete", false);
		return super.getListSize(criteria);
	}
	
	@Override
	public List<CreditcardSetting> getAll(int firstResult, int maxResults,
			String[] sortOrder) throws CoreException {
		CommonCriteria criteria = new CommonCriteria();
		criteria.addEq("delete", false);
		return getList(0, -1, criteria, sortOrder);
	}
	
	@Override
	public Number getAllSize() throws CoreException {
		CommonCriteria criteria = new CommonCriteria();
		criteria.addEq("delete", false);
		return getListSize(criteria);
	}
	
	@Override
	@Transactional(readOnly = false)
	public void delete(CreditcardSetting entity) throws CoreException {
		entity.setDelete(true);
		getDao().update(entity);
	}
	
}
